﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace HeritageAcademy.Shared
{
    public class Duration
    {
        public Dictionary<string, int> Calculate(int number, double singleduration)
        {
            double w = 0, d = 0, h = 0, m = 0;

            Dictionary<string, int> duration = new Dictionary<string, int>();
            duration["minutes"] = 0;
            duration["hours"] = 0;
            duration["days"] = 0;
            duration["weeks"] = 0;

            double x = number * singleduration; // overall duration in minutes
            if ((x / 60) >= 1)
            {
                h = Math.Truncate(x / 60);
                if (((x / 60) / 24) >= 1)
                {
                    d = Math.Truncate((x / 60) / 24);
                    if ((((x / 60) / 24) / 7) >= 1)
                    {
                        w = Math.Truncate(((x / 60) / 24) / 7);
                    }
                }
                else
                {
                    h = Math.Truncate(x / 60);
                }
            }

            m = x - h * 60;
            h = h - d * 24;
            d = d - w * 7;

            duration["minutes"] = Convert.ToInt32(m);
            duration["hours"] = Convert.ToInt32(h);
            duration["days"] = Convert.ToInt32(d);
            duration["weeks"] = Convert.ToInt32(w);
            return duration;
        }

    }
}
